import {fromJS} from "immutable";
import * as types from './type'

const defaultData = fromJS({
    loading: false,
    width: '',
    height: '',
    VerificationCode: '',
    router: '',
    headerNeedFixed:true,
    isScrollToTop:false,
})
// eslint-disable-next-line
export default (state = defaultData, action) => {
    let newVal = action.value;

    if (newVal !== undefined) {

        switch (action.type) {
            //    窗口View -> Height
            case types.SYSTEM_WINDOW_HEIGHT:
                return state.set('height', newVal);

            //    窗口View -> Width
            case types.SYSTEM_WINDOW_WIDTH:
                return state.set('width', newVal);

            //    窗口View -> Height Width 对象结构
            case types.SYSTEM_WINDOW_SIZE:
                /*深度合并 {a:1,b:{c:3,d:4}} {a:1,b:{d:4,e:5}}  => {a:1,b:{c:3,d:4,e:5}}*/
                return state.mergeDeep(newVal);

            //     加载
            case types.SYSTEM_WINDOW_LOADING:
                return state.set('loading', newVal);

            case types.SYSTEM_WINDOW_VERIFICATION_CODE:
                if (newVal)
                    return state.set('VerificationCode', newVal);
                else
                    return state.set('VerificationCode', '');

            case types.SYSTEM_WINDOW_ROUTER:
                return state.set('router', newVal);

            case types.SYSTEM_WINDOW_HEAD_FIXED:
                return state.set('headerNeedFixed',newVal);

            case types.SYSTEM_WINDOW_SCROLL:
                return state.set('isScrollToTop',newVal);

            default:
                return state;
        }
    }
    return state;

}
